package com.ruoyi.wjq.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wjq.domain.FavoriteQuestion;
import com.ruoyi.wjq.service.IFavoriteQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题目收藏Controller
 * 
 * @author wjq
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/wjq/favoritequestion")
public class FavoriteQuestionController extends BaseController
{
    @Autowired
    private IFavoriteQuestionService favoriteQuestionService;

    /**
     * 查询题目收藏列表
     */
    @PreAuthorize("@ss.hasPermi('wjq:favoritequestion:list')")
    @GetMapping("/list")
    public TableDataInfo list(FavoriteQuestion favoriteQuestion)
    {
        startPage();
        List<FavoriteQuestion> list = favoriteQuestionService.selectFavoriteQuestionList(favoriteQuestion);
        return getDataTable(list);
    }

    // 新接口：查询所有状态（包括 del=0 和 del=1）的收藏列表
    @PreAuthorize("@ss.hasPermi('wjq:favoritequestion:list')") // 权限可复用，无需新增
    @GetMapping("/list1") // 路径修改为 /list1，避免冲突
    public TableDataInfo list1(FavoriteQuestion favoriteQuestion) {
        startPage();
        // 调用新的 service 方法，使用同一个 service 实例
        List<FavoriteQuestion> list = favoriteQuestionService.selectFavoriteQuestionList1(favoriteQuestion);
        return getDataTable(list);
    }

    /**
     * 导出题目收藏列表
     */
    @PreAuthorize("@ss.hasPermi('wjq:favoritequestion:export')")
    @Log(title = "题目收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FavoriteQuestion favoriteQuestion)
    {
        List<FavoriteQuestion> list = favoriteQuestionService.selectFavoriteQuestionList(favoriteQuestion);
        ExcelUtil<FavoriteQuestion> util = new ExcelUtil<FavoriteQuestion>(FavoriteQuestion.class);
        util.exportExcel(response, list, "题目收藏数据");
    }

    /**
     * 获取题目收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('wjq:favoritequestion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(favoriteQuestionService.selectFavoriteQuestionById(id));
    }

    /**
     * 新增题目收藏
     */
    @PreAuthorize("@ss.hasPermi('wjq:favoritequestion:add')")
    @Log(title = "题目收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FavoriteQuestion favoriteQuestion)
    {
        return toAjax(favoriteQuestionService.insertFavoriteQuestion(favoriteQuestion));
    }

    /**
     * 修改题目收藏
     */
    @PreAuthorize("@ss.hasPermi('wjq:favoritequestion:edit')")
    @Log(title = "题目收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FavoriteQuestion favoriteQuestion)
    {
        return toAjax(favoriteQuestionService.updateFavoriteQuestion(favoriteQuestion));
    }

    /**
     * 删除题目收藏
     */
    @PreAuthorize("@ss.hasPermi('wjq:favoritequestion:remove')")
    @Log(title = "题目收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(favoriteQuestionService.deleteFavoriteQuestionByIds(ids));
    }
}
